package com.leetcode.alibaba;

import java.util.Stack;

/**
 * 输入：
 * ["PSH1","PSH2","POP","POP"]
 * 复制
 * 返回值：
 * 1,2
 * 说明：
 * "PSH1":代表将1插入队列尾部
 * "PSH2":代表将2插入队列尾部
 * "POP“:代表删除一个元素，先进先出=>返回1
 * "POP“:代表删除一个元素，先进先出=>返回2
 */
public class 两个栈实现队列 {

	public static void main(String[] args) {
		MyList list = new MyList();
		list.push(1);
		list.push(2);
		list.push(3);
		System.out.println(list.pop());
		System.out.println(list.pop());
		System.out.println(list.pop());
	}
}

class MyList {
	Stack<Integer> stack1 = new Stack<>();
	Stack<Integer> stack2 = new Stack<>();

	public void push(int node) {
		stack1.push(node);
	}

	public int pop() {
		if (stack2.isEmpty()) {
			while (!stack1.isEmpty()) {
				stack2.push(stack1.pop());
			}
		}
		return stack2.pop();
	}
}
